//
//  ViewController.m
//  NewPagedFlowViewDemo
//
//  Copyright © 2016年 Mars. All rights reserved.
//  Designed By PageGuo,
//  QQ:799573715
//  github:https://github.com/PageGuo/NewPagedFlowView

#import "ViewController.h"
#import "NewPagedFlowView.h"
#import "PGIndexBannerSubiew.h"
#import "CustomViewController.h"
#import "UIImageView+WebCache.h"
#define Width [UIScreen mainScreen].bounds.size.width

@interface ViewController ()<NewPagedFlowViewDelegate, NewPagedFlowViewDataSource>

/**
 *  图片数组
 */
@property (nonatomic, strong) NSMutableArray *imageArray;

/**
 *  指示label
 */
@property (nonatomic, strong) UILabel *indicateLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"NewPagedFlowView";
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Custom" style:UIBarButtonItemStyleDone target:self action:@selector(pushCustomVC)];
    
    [self.imageArray removeAllObjects];
    for (int index = 0; index < 5; index++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"Yosemite%02d",index]];
        [self.imageArray addObject:image];
    }
    
    [self setupUI];
    self.imageView.backgroundColor = [UIColor yellowColor];
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:@"https://img.lmchaoshi.com/cardbanner/1531103578768.jpg"]];
}

#pragma mark --push控制器
- (void)pushCustomVC {

    //完全自定义,注意两处 #warning !!!!!!!!!1
    CustomViewController *customVC = [[CustomViewController alloc] init];
    
    [self.navigationController pushViewController:customVC animated:YES];
}

- (void)setupUI {
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    NewPagedFlowView *pageFlowView = [[NewPagedFlowView alloc] initWithFrame:CGRectMake(0, 72, Width, Width )];
    pageFlowView.delegate = self;
    pageFlowView.dataSource = self;
    pageFlowView.minimumPageAlpha = 0.3;//非当前页的透明比例
    pageFlowView.leftRightMargin = 0;//左右间距
    pageFlowView.topBottomMargin = 0;
    pageFlowView.hiddenPageControll = YES;
    pageFlowView.orginPageCount = self.imageArray.count;//原始页数
    pageFlowView.isOpenAutoScroll = YES;//是否开启自动滚动
    pageFlowView.autoTime = 2.0;//设置定时器秒数
    pageFlowView.isCarousel = YES;//是否开启无限轮播
    pageFlowView.orientation = NewPagedFlowViewOrientationVertical;//横向纵向
    
//    pageFlowView.urlImageDataSource = self.imageArray;//传入网络数据
    pageFlowView.imageDataSource = self.imageArray;//传入网络数据

    pageFlowView.imgProportion = 10/16.0;//设置图片比例
    pageFlowView.cornerRadius = 5;//设置圆角
    pageFlowView.contentMode = UIViewContentModeScaleToFill;
    [pageFlowView reloadData];//设置完数据刷新数据
    //初始化pageControl
    [self.view addSubview:pageFlowView];
    
    //添加到主view上
    [self.view addSubview:self.indicateLabel];

}


#pragma mark NewPagedFlowView Delegate
#pragma mark =========点击了第几页=========
- (void)didSelectCell:(UIView *)subView withSubViewIndex:(NSInteger)subIndex {
    
    NSLog(@"点击了第%ld张图",(long)subIndex + 1);
    
    self.indicateLabel.text = [NSString stringWithFormat:@"点击了第%ld张图",(long)subIndex + 1];
}
#pragma mark =========滚动到了第几页=========
- (void)didScrollToPage:(NSInteger)pageNumber inFlowView:(NewPagedFlowView *)flowView {
    
    NSLog(@"ViewController 滚动到了第%d页",pageNumber);
}




#pragma mark --懒加载
- (NSMutableArray *)imageArray {
    if (_imageArray == nil) {
        _imageArray = [NSMutableArray array];
        [_imageArray addObjectsFromArray:@[@"https://img.lmchaoshi.com/cardbanner/1531103419428.jpg",@"https://img.lmchaoshi.com/cardbanner/1531103578768.jpg",@"https://img.lmchaoshi.com/cardbanner/1531103811960.jpg"]];
    }
    return _imageArray;
}

- (UILabel *)indicateLabel {
    
    if (_indicateLabel == nil) {
        _indicateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 400, Width, 16)];
        _indicateLabel.textColor = [UIColor blueColor];
        _indicateLabel.font = [UIFont systemFontOfSize:16.0];
        _indicateLabel.textAlignment = NSTextAlignmentCenter;
        _indicateLabel.text = @"指示Label";
    }
    
    return _indicateLabel;
}

@end
